<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel common\models\qywx\DepartmentSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Departments');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="department-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a(Yii::t('app', 'Create Department'), ['create'], ['class' => 'btn btn-success']) ?>
        <?= Html::a(Yii::t('app', 'Sync Department in QYWX'), ['sync'], ['class' => 'btn btn-primary']) ?>
    </p>
    <?= GridView::widget([
        'tableOptions' => ['class' => 'table table-condensed table-bordered table-striped table-hover'],
        'pager'        => [
//            'class'          => GoPager::className(),
            'nextPageLabel'  => '下一页',
            'prevPageLabel'  => '上一页',
            'firstPageLabel' => '首页',
            'lastPageLabel'  => '末页',
            'options'        => [
                'class' => 'pagination pagination-sm m-t-none m-b-none',
            ],
        ],
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'department_id',
            'department_qywx_id',
            'department_name',
            'department_parent_qywx_id',
            'department_order',
            // 'department_memo',
            // 'department_created_by',
            // 'department_created_at',
            // 'department_updated_by',
            // 'department_updated_at',

            [
                'class'         => 'yii\grid\ActionColumn',
                'template'      => '{get-user-list} {sync} {view} {update} {delete} {cascade-delete}',
                'header'        => '操作',
                'headerOptions' => ['class' => 'text-center no-margin'],
                'buttons'       => [
                    'get-user-list' => function($url, $model, $key) {
                        $options = [
                            'title' => Yii::t('app', 'Get User List'),
                            'data-id' => $key,
                        ];
                        return Html::a('<span class="	glyphicon glyphicon-user edit-class"></span>', $url, $options);
                    },
                    'sync' => function($url, $model, $key) {
                        $options = [
                            'title' => Yii::t('app', 'Sync Child Department List'),
                            'data-id' => $key,
                        ];
                        return Html::a('<span class="	glyphicon glyphicon-cog edit-class"></span>', $url, $options);
                    },
                    'cascade-delete' => function($url, $model, $key) {
                        $options = [
                            'title' => Yii::t('app', 'Cascade Delete'),
                            'data-id' => $key,
                        ];
                        return Html::a('<span class="	glyphicon glyphicon-user edit-class"></span>', $url, $options);
                    },
                ],
            ],
        ],
    ]); ?>
</div>
